<!DOCTYPE html>
<html>
<head>
    <title>我的收藏</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <link rel="stylesheet" href="/css/strategy.css" />
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script type="text/javascript">
        $(function () {
            //获取当前用户
            var user = JSON.parse(sessionStorage.getItem("user"));
            //总页数
            var pages = 1;
            //当前页
            var currentPage = 1;
            //页面容量
            var pageSize = 3;
            //内容
            var collectionData = [];

            var flag = 1;

            //导航条的点击事件
            $(".nav-link").click(function () {
                collectionData = [];
                pages = 1;
                currentPage = 1;
                flag = $(this).data("flag");
                if (flag == 1){
                    strategydetail();
                } else if (flag == 2){
                    travel();
                }else if (flag == 3){
                    daily();
                }
            })
            
            $.get("/myCollections/strategydetaiAll" ,{userId: user.id} ,function (data) {
                $("#allstrategydetai").html('('+data+')');
            })
            $.get("/myCollections/travelAll" ,{userId: user.id} ,function (data) {
                $("#alltravelAll").html('('+data+')');
            })
            $.get("/myCollections/dailyAll" ,{userId: user.id} ,function (data) {
                $("#alldailyAll").html('('+data+')');
            })


            //获取攻略
            function strategydetail() {
                $.get("/users/" + user.id+ "/myCollections", {strategydetailId:1,
                    currentPage: currentPage,
                    pageSize: pageSize
                }, function (data) {
                    //不用插件,模板不一样
                    var coverUrl = "";
                    var title = "";
                    var url = "";
                    if (data.list.length != 0){
                        for (var i = 0; i < data.list.length; i++) {
                            if (data.list[i].strategydetail) {
                                coverUrl = data.list[i].strategydetail.coverUrl;
                                title = "攻略: " + data.list[i].strategydetail.title;
                                url = "/strategyDetails.html?id=" + data.list[i].strategydetail.id;
                            }
                            else {
                                $("#pills-1").html("你暂时没有收藏")
                            }
                            collectionData += '<dd>' +
                                '            <a href="' + url + '">' +
                                '                <img src="' + coverUrl + '" width="100%">' +
                                '                <h6 class="title">' + title + '</h6>' +
                                '                <p>收藏时间<span>' + data.list[i].collectTime + '</span>' +
                                '                </p>' +
                                '            </a>' +
                                '        </dd>';
                        }
                    }else {
                        collectionData = "你还没有收藏攻略";
                    }
                    $(".list").html(collectionData);
                    pages = data.pages;
                });
                currentPage++;
            }

            //获取游记
            function travel() {
                $.get("/users/" + user.id + "/myCollections", {
                    travelId:1,
                    currentPage: currentPage,
                    pageSize: pageSize
                }, function (data) {
                    //不用插件,模板不一样
                    var coverUrl = "";
                    var title = "";
                    var url = "";
                    if (data.list.length != 0){
                        for (var i = 0; i < data.list.length; i++) {
                            if (data.list[i].travel) {
                                coverUrl = data.list[i].travel.coverUrl;
                                title = "游记: " + data.list[i].travel.title;
                                url = "/travelContent.html?id=" + data.list[i].travel.id;
                            }
                            collectionData += '<dd>' +
                                '            <a href="' + url + '">' +
                                '                <img src="' + coverUrl + '" width="100%">' +
                                '                <h6 class="title">' + title + '</h6>' +
                                '                <p>收藏时间<span>' + data.list[i].collectTime + '</span>' +
                                '                </p>' +
                                '            </a>' +
                                '        </dd>';
                        }
                    }else {
                        collectionData = "你还没有收藏游记";
                    }
                    $(".list2").html(collectionData);
                    pages = data.pages;
                });
                currentPage++;
            }

            //日报
            function daily() {
                $.get("/users/" + user.id + "/myCollections", {
                    dailyId:1,
                    currentPage: currentPage,
                    pageSize: pageSize
                }, function (data) {
                    //不用插件,模板不一样
                    var coverUrl = "";
                    var title = "";
                    var url = "";
                    if (data.list.length!=0){
                        for (var i = 0; i < data.list.length; i++) {
                            if (data.list[i].daily) {
                                coverUrl = data.list[i].daily.coverUrl;
                                title = "日报: " + data.list[i].daily.title;
                                url = "/newsContent.html?id=" + data.list[i].daily.id;
                            }
                            collectionData += '<dd>' +
                                '            <a href="' + url + '">' +
                                '                <img src="' + coverUrl + '" width="100%">' +
                                '                <h6 class="title">' + title + '</h6>' +
                                '                <p>收藏时间<span>' + data.list[i].collectTime + '</span>' +
                                '                </p>' +
                                '            </a>' +
                                '        </dd>';
                        }
                    }else {
                        collectionData = "你还没有收藏日报";
                    }

                    $(".list3").html(collectionData);
                    pages = data.pages;
                });
                currentPage++;
            }

            //默认查询一次
            if (flag == 1){
                strategydetail();
            } else if (flag == 2){
                travel();
            }else if (flag == 3){
                daily();
            }




            function query(){
                if (flag == 1){
                    strategydetail();
                } else if (flag == 2){
                    travel();
                }else if (flag == 3){
                    daily();
                }
            }

            //滚动到底部触发事件
            $(window).scroll(function () {
                if ($(window).height() + $(document).scrollTop() >= $(document).height()-1){
                    if (currentPage <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底部',
                            autoClose: 1000,
                            position: 'center'  // center: 居中; bottom: 底部
                        });
                    }
                }
            })


        })
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>

    </div>
</div>



<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active show" id="pills-1-tab" data-toggle="pill" href="#pills-1" data-flag="1">
            <span >攻略</span>
            <span  id="allstrategydetai"></span>
        </a>
    </li>
    <li class="nav-item" >
        <a data-id="2" class="nav-link" id="pills-2-tab" data-toggle="pill" href="#pills-2" data-flag="2">
            <span >游记</span>
            <span  id="alltravelAll"></span>
        </a>
    </li>
    <li class="nav-item" >
        <a data-id="3" class="nav-link" id="pills-3-tab" data-toggle="pill" href="#pills-3" data-flag="3">
        <span >日報</span>
        <span  id="alldailyAll"></span>
        </a>
    </li>
</ul>
<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-1">
        <div class="container strategyDetails">
            <h6>攻略收藏</h6>
            <div id="travelall">
                        <div class="container collections">
                            <d1 class="list"></d1>
                        </div>
            </div>
        </div>
    </div>

    <div class="tab-pane fade" id="pills-2">
        <div class="container">
            <h6>游记收藏</h6>
            <div id="allTravels">
                        <div class="container collections">
                            <d1 class="list2"></d1>
                        </div>
            </div>
        </div>
    </div>



    <div class="tab-pane fade" id="pills-3">
        <div class="container">
        <h6>日报收藏</h6>
        <div id="alldaily">
                    <div class="container collections">
                        <d1 class="list3"></d1>
                    </div>
        </div>
        </div>
    </div>
</div>
</body>
</html>
